package SortMethod;

public class shellSort {

    private shellSort(){}

    //希尔排序，通过优化插入排序的巅峰之作
    public static <E extends Comparable<E>> void sort(E[] arr){
        int len = arr.length;
        //每次循环就将间隔缩短一半，直到缩短为1
        int h = len / 2;
        while(h >= 1){
            //从
            for (int i = h;i < len;i++){
                int j = i;
                E temp = arr[i];
                for (; j > 0; j-=h) {
                    if (j - h >= 0&&temp.compareTo(arr[j - h]) < 0){
                        arr[j] = arr[j - h];
                    } else {
                        break;
                    }
                }
                arr[j] = temp;
            }
            h /= 2;
        }
    }
}
